package org.sjs.dreamfly.common.util

import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import org.sjs.dreamfly.biz.movie.detail.MovieDetailActivity
import org.sjs.dreamfly.biz.news.NewsDetailActivity
import org.sjs.dreamfly.biz.personal.PersonalActivity
import org.sjs.dreamfly.biz.shortvideo.ShortVideoActivity
import org.sjs.dreamfly.player.PlayerActivity
import org.sjs.dreamfly.model.MovieInfo

object Router {

    const val KEY_INDEX = "key_index"
    const val KEY_MOVIE_INFO = "key_movieInfo"
    const val KEY_TITLE = "key_title"
    const val KEY_URL = "key_url"
    const val KEY_ORIENTATION = "key_orientation"
    const val KEY_CHANNEL_TYPE = "key_channel_type"

    const val ORIENTATION_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    const val ORIENTATION_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

    fun launchPlayer(url: String?, title: String?, orientation: Int = ORIENTATION_PORTRAIT) {
        LogUtil.d("url:$url, title:$title")
        PhemonUtils.getApplication().startActivity(Intent(PhemonUtils.getApplication(), PlayerActivity::class.java).apply {
            this.putExtra(KEY_URL, url)
            this.putExtra(KEY_TITLE, title)
            this.putExtra(KEY_ORIENTATION, orientation)
            this.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            this.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
        })
    }

    fun launchMovieDetail(movieInfo: MovieInfo, channelType: String) {
        PhemonUtils.getApplication().startActivity(Intent(PhemonUtils.getApplication(), MovieDetailActivity::class.java).apply {
            this.putExtra(KEY_MOVIE_INFO, movieInfo.toString())
            this.putExtra(KEY_CHANNEL_TYPE, channelType)
            this.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            this.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
        })
    }

    fun launchNewsDetail(url: String) {
        PhemonUtils.getApplication().startActivity(Intent(PhemonUtils.getApplication(), NewsDetailActivity::class.java).apply {
            this.putExtra(KEY_URL, url)
            this.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            this.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
        })
    }

    fun launchShortVideoDetail(position: Int) {
        PhemonUtils.getApplication().startActivity(Intent(PhemonUtils.getApplication(), ShortVideoActivity::class.java).apply {
            this.putExtra(KEY_INDEX, position)
            this.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            this.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
        })
    }

    fun launchPersonalActivity(context: Context? = null) {
        PhemonUtils.getApplication().startActivity(Intent(context?:PhemonUtils.getApplication(), PersonalActivity::class.java).apply {
            this.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            this.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
        })
    }
}